package lk.icta.core.entity;

import lk.icta.common.entity.BaseEntity;
import lk.icta.common.entity.GNDivision;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.Set;

/**
 * @author Tharanga Punchihewa
 * @author Duminda Dharmakeerthi
 */
@Entity
@Table(schema = "ELAND_RAIL")
@NamedQueries({
        @NamedQuery(name = "getAllActiveSchedule", query = "SELECT s FROM Schedule s WHERE s.status =:status"),
        @NamedQuery(name = "getScheduleById", query = "SELECT s FROM Schedule s WHERE s.id = :id"),
        @NamedQuery(
                name = "getAllActiveSchedulesByDSDivision",
                query = "SELECT s FROM Schedule s WHERE s.status =:status AND s.gnDivision IN (SELECT gn FROM GNDivision gn WHERE gn.dsDivision.id = :dsDivisionId)"
        ),
        //  @NamedQuery(name = "getAllActiveScheduleByGNdivision", query = "SELECT s FROM Schedule s WHERE s.status =:status AND s.gnDivision.id = :gnId ") ,
        @NamedQuery(name = "getScheduleByDate", query = "SELECT s FROM Schedule s WHERE s.startDate = :startDate"),
        @NamedQuery(name = "getScheduleByLandId", query = "SELECT s FROM Schedule s WHERE :landId MEMBER OF s.landList")
})
public class Schedule extends BaseEntity {
    public enum Status {
        INACTIVE, /**
         * 0 - Active record
         */
        ACTIVE      /** 1 - Inactive record */
    }

    /**
     * status - The record is active or inactive .. etc/ null
     */
    @Column(nullable = false)
    private Status status;
    /**
     * Start date of the Schedule
     */
    @Column(nullable = true)
    @Temporal(value = TemporalType.DATE)
    private Date startDate;
    /**
     * End date of the Schedule
     */
    @Column(nullable = true)
    @Temporal(value = TemporalType.DATE)
    private Date endDate;

    @Column(nullable = true)
    private String task;

    @ManyToOne
    @JoinColumn(nullable = false)
    private GNDivision gnDivision;

    /**
     * The Land List to be visited
     */
    @ManyToMany(fetch = FetchType.EAGER)
    @JoinTable(schema = "ELAND_RAIL")
    private Set<Land> landList;

    @Embedded
    private LifeCycleInfo lifeCycleInfo = new LifeCycleInfo();

    public Status getStatus() {
        return status;
    }

    public void setStatus(Status status) {
        this.status = status;
    }

    public Date getStartDate() {
        return startDate;
    }

    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    public Date getEndDate() {
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    public String getTask() {
        return task;
    }

    public void setTask(String task) {
        this.task = task;
    }

    public Set<Land> getLandList() {
        return landList;
    }

    public void setLandList(Set<Land> landList) {
        this.landList = landList;
    }

    public LifeCycleInfo getLifeCycleInfo() {
        return lifeCycleInfo;
    }

    public void setLifeCycleInfo(LifeCycleInfo lifeCycleInfo) {
        this.lifeCycleInfo = lifeCycleInfo;
    }

    public GNDivision getGnDivision() {
        return gnDivision;
    }

    public void setGnDivision(GNDivision gnDivision) {
        this.gnDivision = gnDivision;
    }
}
